package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;
import java.io.Serializable;
import java.util.Arrays;

/* loaded from: classes.dex */
public final class Envelope extends Geometry implements Serializable {
    private static final long serialVersionUID = 2;
    Envelope2D a = new Envelope2D();
    double[] b;

    @Override // com.esri.core.geometry.Geometry
    public int getDimension() {
        return 2;
    }

    public Envelope(Point point, double d, double d2) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        this.a.setEmpty();
        if (point.isEmpty()) {
            return;
        }
        a(point, d, d2);
    }

    Envelope(Envelope2D envelope2D) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        this.a.setCoords(envelope2D);
        this.a.normalize();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Envelope(VertexDescription vertexDescription) {
        if (vertexDescription == null) {
            throw new IllegalArgumentException();
        }
        this.m_description = vertexDescription;
        this.a.setEmpty();
    }

    Envelope(VertexDescription vertexDescription, Envelope2D envelope2D) {
        if (vertexDescription == null) {
            throw new IllegalArgumentException();
        }
        this.m_description = vertexDescription;
        this.a.setCoords(envelope2D);
        this.a.normalize();
    }

    public Envelope() {
        this.m_description = VertexDescriptionDesignerImpl.d();
        this.a.setEmpty();
    }

    public Envelope(Point point) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        this.a.setEmpty();
        if (point.isEmpty()) {
            return;
        }
        a(point);
    }

    public Envelope(double d, double d2, double d3, double d4) {
        this.m_description = VertexDescriptionDesignerImpl.d();
        setCoords(d, d2, d3, d4);
    }

    public void setCoords(double d, double d2, double d3, double d4) {
        i();
        this.a.setCoords(d, d2, d3, d4);
    }

    void a(Point[] pointArr) {
        i();
        setEmpty();
        for (Point point : pointArr) {
            merge(point);
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(Envelope2D envelope2D) {
        i();
        if (!envelope2D.isValid()) {
            throw new IllegalArgumentException();
        }
        this.a.setCoords(envelope2D);
    }

    @Override // com.esri.core.geometry.Geometry
    public void setEmpty() {
        i();
        this.a.setEmpty();
    }

    @Override // com.esri.core.geometry.Geometry
    public boolean isEmpty() {
        return this.a.isEmpty();
    }

    public double getWidth() {
        return this.a.getWidth();
    }

    public double getHeight() {
        return this.a.getHeight();
    }

    public double getCenterX() {
        return this.a.getCenterX();
    }

    public double getCenterY() {
        return this.a.getCenterY();
    }

    Point2D a() {
        return this.a.getCenter();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(Point2D point2D) {
        i();
        this.a.merge(point2D);
    }

    public void merge(Envelope envelope) {
        i();
        if (envelope.isEmpty()) {
            return;
        }
        VertexDescription vertexDescription = envelope.m_description;
        if (vertexDescription != this.m_description) {
            mergeVertexDescription(vertexDescription);
        }
        this.a.merge(envelope.a);
        int attributeCount = vertexDescription.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int semantics = vertexDescription.getSemantics(i);
            int componentCount = VertexDescription.getComponentCount(semantics);
            for (int i2 = 0; i2 < componentCount; i2++) {
                Envelope1D queryInterval = envelope.queryInterval(semantics, i2);
                Envelope1D queryInterval2 = queryInterval(semantics, i2);
                queryInterval2.merge(queryInterval);
                a(semantics, i2, queryInterval2);
            }
        }
    }

    public void merge(Point point) {
        i();
        if (point.l()) {
            return;
        }
        VertexDescription vertexDescription = point.m_description;
        if (this.m_description != vertexDescription) {
            mergeVertexDescription(vertexDescription);
        }
        if (isEmpty()) {
            a(point);
            return;
        }
        this.a.merge(point.a());
        int attributeCount = vertexDescription.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int _getSemanticsImpl = vertexDescription._getSemanticsImpl(i);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i2 = 0; i2 < componentCount; i2++) {
                double a = point.a(_getSemanticsImpl, i2);
                Envelope1D queryInterval = queryInterval(_getSemanticsImpl, i2);
                queryInterval.merge(a);
                a(_getSemanticsImpl, i2, queryInterval);
            }
        }
    }

    void a(Point point, double d, double d2) {
        this.a.setCoords(point.a(), d, d2);
        VertexDescription vertexDescription = point.m_description;
        int attributeCount = vertexDescription.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int _getSemanticsImpl = vertexDescription._getSemanticsImpl(i);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i2 = 0; i2 < componentCount; i2++) {
                double a = point.a(_getSemanticsImpl, i2);
                a(_getSemanticsImpl, i2, a, a);
            }
        }
    }

    void a(Point point) {
        this.a.setCoords(point.a[0], point.a[1]);
        VertexDescription vertexDescription = point.m_description;
        int attributeCount = vertexDescription.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int _getSemanticsImpl = vertexDescription._getSemanticsImpl(i);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i2 = 0; i2 < componentCount; i2++) {
                double a = point.a(_getSemanticsImpl, i2);
                a(_getSemanticsImpl, i2, a, a);
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void b(Envelope2D envelope2D) {
        i();
        this.a.merge(envelope2D);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i, int i2, double d, double d2) {
        a(i, i2, new Envelope1D(d, d2));
    }

    public void reaspect(double d, double d2) {
        i();
        this.a.reaspect(d, d2);
    }

    public void inflate(double d, double d2) {
        i();
        this.a.inflate(d, d2);
    }

    @Override // com.esri.core.geometry.Geometry
    public void applyTransformation(Transformation2D transformation2D) {
        i();
        this.a = transformation2D.a(this.a);
    }

    @Override // com.esri.core.geometry.Geometry
    void applyTransformation(Transformation3D transformation3D) {
        i();
        if (this.a.isEmpty()) {
            return;
        }
        Envelope3D envelope3D = new Envelope3D();
        queryEnvelope3D(envelope3D);
        if (envelope3D.isEmptyZ()) {
            envelope3D.setEmpty();
        } else {
            transformation3D.transform(envelope3D);
        }
    }

    @Override // com.esri.core.geometry.Geometry
    public void copyTo(Geometry geometry) {
        if (geometry.getType() != getType()) {
            throw new IllegalArgumentException();
        }
        Envelope envelope = (Envelope) geometry;
        geometry.i();
        envelope.m_description = this.m_description;
        envelope.a.setCoords(this.a);
        envelope.a(this.m_description.c() - 2);
        a(this.b, 0, envelope.b, 0, (this.m_description.c() - 2) * 2);
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry createInstance() {
        return new Envelope(this.m_description);
    }

    @Override // com.esri.core.geometry.Geometry
    public double calculateArea2D() {
        return this.a.getArea();
    }

    @Override // com.esri.core.geometry.Geometry
    public double calculateLength2D() {
        return this.a.getLength();
    }

    @Override // com.esri.core.geometry.Geometry
    public Geometry.Type getType() {
        return Geometry.Type.ENVELOPE;
    }

    @Override // com.esri.core.geometry.Geometry
    public void queryEnvelope(Envelope envelope) {
        copyTo(envelope);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // com.esri.core.geometry.Geometry
    public void queryEnvelope2D(Envelope2D envelope2D) {
        envelope2D.xmin = this.a.xmin;
        envelope2D.ymin = this.a.ymin;
        envelope2D.xmax = this.a.xmax;
        envelope2D.ymax = this.a.ymax;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // com.esri.core.geometry.Geometry
    public void queryEnvelope3D(Envelope3D envelope3D) {
        envelope3D.xmin = this.a.xmin;
        envelope3D.ymin = this.a.ymin;
        envelope3D.xmax = this.a.xmax;
        envelope3D.ymax = this.a.ymax;
        envelope3D.setCoords(this.a.xmin, this.a.ymin, a(0, 1, 0), this.a.xmax, this.a.ymax, a(1, 1, 0));
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    @Override // com.esri.core.geometry.Geometry
    public Envelope1D queryInterval(int i, int i2) {
        Envelope1D envelope1D = new Envelope1D();
        envelope1D.setCoords(a(0, i, i2), a(1, i, i2));
        return envelope1D;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public void a(int i, int i2, Envelope1D envelope1D) {
        i();
        if (i != 0) {
            a(0, i, i2, envelope1D.vmin);
            a(1, i, i2, envelope1D.vmax);
        } else if (i2 == 0) {
            this.a.xmin = envelope1D.vmin;
            this.a.xmax = envelope1D.vmax;
        } else if (i2 == 1) {
            this.a.ymin = envelope1D.vmin;
            this.a.ymax = envelope1D.vmax;
        } else {
            throw new IndexOutOfBoundsException();
        }
    }

    void a(Point2D[] point2DArr) {
        if (point2DArr == null || point2DArr.length < 4 || this.a.isEmpty()) {
            throw new IllegalArgumentException();
        }
        this.a.queryCorners(point2DArr);
    }

    public void queryCornerByVal(int i, Point point) {
        point.a(this.m_description);
        int attributeCount = getDescription().getAttributeCount() - 1;
        if (i == 0) {
            for (int i2 = 0; i2 < attributeCount; i2++) {
                int semantics = this.m_description.getSemantics(i2);
                int componentCount = VertexDescription.getComponentCount(semantics);
                for (int i3 = 0; i3 < componentCount; i3++) {
                    point.a(semantics, i3, a(0, semantics, i3));
                }
            }
            point.setXY(this.a.xmin, this.a.ymin);
        } else if (i == 1) {
            for (int i4 = 0; i4 < attributeCount; i4++) {
                int semantics2 = this.m_description.getSemantics(i4);
                int componentCount2 = VertexDescription.getComponentCount(semantics2);
                for (int i5 = 0; i5 < componentCount2; i5++) {
                    point.a(semantics2, i5, a(1, semantics2, i5));
                }
            }
            point.setXY(this.a.xmin, this.a.ymax);
        } else if (i == 2) {
            for (int i6 = 0; i6 < attributeCount; i6++) {
                int semantics3 = this.m_description.getSemantics(i6);
                int componentCount3 = VertexDescription.getComponentCount(semantics3);
                for (int i7 = 0; i7 < componentCount3; i7++) {
                    point.a(semantics3, i7, a(0, semantics3, i7));
                }
            }
            point.setXY(this.a.xmax, this.a.ymax);
        } else if (i == 3) {
            for (int i8 = 0; i8 < attributeCount; i8++) {
                int semantics4 = this.m_description.getSemantics(i8);
                int componentCount4 = VertexDescription.getComponentCount(semantics4);
                for (int i9 = 0; i9 < componentCount4; i9++) {
                    point.a(semantics4, i9, a(1, semantics4, i9));
                }
            }
            point.setXY(this.a.xmax, this.a.ymin);
        } else {
            throw new IndexOutOfBoundsException();
        }
    }

    void a(int i, Point2D point2D) {
        Point2D queryCorner = this.a.queryCorner(i);
        point2D.setCoords(queryCorner.x, queryCorner.y);
    }

    void a(int i) {
        i();
        double[] dArr = this.b;
        if (dArr == null) {
            this.b = new double[i * 2];
        } else if (dArr.length < i * 4) {
            double[] dArr2 = new double[i * 2];
            System.arraycopy(dArr, 0, dArr2, 0, dArr.length);
            this.b = dArr2;
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void b(int i) {
        if (this.a.isEmpty()) {
            return;
        }
        int a = this.m_description.a(this.m_description.getAttributeIndex(i)) - 2;
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c() - 2;
        if (c > componentCount) {
            int d = d(0);
            int i2 = a + componentCount;
            for (int i3 = i2; i3 < c * 2; i3++) {
                double[] dArr = this.b;
                int i4 = d + i3;
                dArr[i4 - componentCount] = dArr[i4];
            }
            int d2 = d(1) - componentCount;
            while (i2 < c) {
                double[] dArr2 = this.b;
                int i5 = d2 + i2;
                dArr2[i5 - componentCount] = dArr2[i5];
                i2++;
            }
        }
    }

    @Override // com.esri.core.geometry.Geometry
    void c(int i) {
        int a = this.m_description.a(this.m_description.getAttributeIndex(i)) - 2;
        int componentCount = VertexDescription.getComponentCount(i);
        int c = this.m_description.c() - 2;
        a(c);
        int d = d(0);
        int d2 = d(1);
        int i2 = d2 - componentCount;
        for (int i3 = (c - componentCount) - 1; i3 >= 0; i3--) {
            double[] dArr = this.b;
            dArr[d2 + i3] = dArr[i2 + i3];
        }
        for (int i4 = c - 1; i4 >= a + componentCount; i4--) {
            double[] dArr2 = this.b;
            int i5 = d + i4;
            dArr2[i5] = dArr2[i5 - componentCount];
            int i6 = d2 + i4;
            dArr2[i6] = dArr2[i6 - componentCount];
        }
        double defaultValue = VertexDescription.getDefaultValue(i);
        for (int i7 = 0; i7 < componentCount; i7++) {
            double[] dArr3 = this.b;
            dArr3[d + a + i7] = defaultValue;
            dArr3[d2 + a + i7] = defaultValue;
        }
    }

    static void a(double[] dArr, int i, double[] dArr2, int i2, int i3) {
        for (int i4 = 0; i4 < i3; i4++) {
            dArr2[i2 + i4] = dArr[i4 + i];
        }
    }

    double a(int i, int i2, int i3) {
        if (this.a.isEmpty()) {
            throw new GeometryException("This operation was performed on an Empty Geometry.");
        }
        if (i2 == 0) {
            if (i != 0) {
                Envelope2D envelope2D = this.a;
                return i3 != 0 ? envelope2D.ymax : envelope2D.xmax;
            }
            Envelope2D envelope2D2 = this.a;
            return i3 != 0 ? envelope2D2.ymin : envelope2D2.xmin;
        } else if (i3 >= VertexDescription.getComponentCount(i2)) {
            throw new IndexOutOfBoundsException();
        } else {
            int attributeIndex = this.m_description.getAttributeIndex(i2);
            if (attributeIndex >= 0) {
                if (this.b != null) {
                    a(this.m_description.c() - 2);
                }
                return this.b[((d(i) + this.m_description.a(attributeIndex)) - 2) + i3];
            }
            return VertexDescription.getDefaultValue(i2);
        }
    }

    void a(int i, int i2, int i3, double d) {
        i();
        if (i2 == 0) {
            if (i != 0) {
                if (i3 != 0) {
                    this.a.ymax = d;
                } else {
                    this.a.xmax = d;
                }
            } else if (i3 != 0) {
                this.a.ymin = d;
            } else {
                this.a.xmin = d;
            }
        }
        if (i3 >= VertexDescription.getComponentCount(i2)) {
            throw new IndexOutOfBoundsException();
        }
        if (!e(i2)) {
            if (VertexDescription.isDefaultValue(i2, d)) {
                return;
            }
            addAttribute(i2);
        }
        int attributeIndex = this.m_description.getAttributeIndex(i2);
        if (this.b == null) {
            a(this.m_description.c() - 2);
        }
        this.b[((d(i) + this.m_description.a(attributeIndex)) - 2) + i3] = d;
    }

    int b(int i, int i2, int i3) {
        return (int) a(i, i2, i3);
    }

    int d(int i) {
        return i * (this.m_description.c() - 2);
    }

    boolean c(Envelope2D envelope2D) {
        return this.a.isIntersecting(envelope2D);
    }

    public boolean intersect(Envelope envelope) {
        i();
        Envelope2D envelope2D = new Envelope2D();
        envelope.queryEnvelope2D(envelope2D);
        return this.a.intersect(envelope2D);
    }

    public boolean isIntersecting(Envelope envelope) {
        return this.a.isIntersecting(envelope.a);
    }

    public void centerAt(Point point, double d, double d2) {
        i();
        if (point.isEmpty()) {
            setEmpty();
        } else {
            a(point, d, d2);
        }
    }

    public void offset(double d, double d2) {
        i();
        this.a.offset(d, d2);
    }

    public void normalize() {
        i();
        this.a.normalize();
    }

    Point2D b() {
        return this.a.getCenter();
    }

    public Point getCenter() {
        Point point = new Point(this.m_description);
        if (isEmpty()) {
            return point;
        }
        int attributeCount = this.m_description.getAttributeCount();
        for (int i = 1; i < attributeCount; i++) {
            int _getSemanticsImpl = this.m_description._getSemanticsImpl(i);
            int componentCount = VertexDescription.getComponentCount(_getSemanticsImpl);
            for (int i2 = 0; i2 < componentCount; i2++) {
                point.a(_getSemanticsImpl, i2, (a(0, _getSemanticsImpl, i2) + a(1, _getSemanticsImpl, i2)) * 0.5d);
            }
        }
        point.setXY(this.a.getCenterX(), this.a.getCenterY());
        return point;
    }

    public void centerAt(Point point) {
        i();
        if (point.isEmpty()) {
            setEmpty();
        } else {
            this.a.centerAt(point.getX(), point.getY());
        }
    }

    public Point getLowerLeft() {
        return this.a.getLowerLeft();
    }

    public Point getUpperRight() {
        return this.a.getUpperRight();
    }

    public Point getLowerRight() {
        return this.a.getLowerRight();
    }

    public Point getUpperLeft() {
        return this.a.getUpperLeft();
    }

    public boolean contains(Point point) {
        if (point.isEmpty()) {
            return false;
        }
        return this.a.contains(point.getX(), point.getY());
    }

    public boolean contains(Envelope envelope) {
        return this.a.contains(envelope.a);
    }

    public boolean equals(Object obj) {
        if (obj == this) {
            return true;
        }
        if (obj instanceof Envelope) {
            Envelope envelope = (Envelope) obj;
            if (this.m_description != envelope.m_description) {
                return false;
            }
            if (isEmpty()) {
                return envelope.isEmpty();
            } else if (this.a.equals(envelope.a)) {
                int c = (this.m_description.c() - 2) * 2;
                for (int i = 0; i < c; i++) {
                    if (this.b[i] != envelope.b[i]) {
                        return false;
                    }
                }
                return true;
            } else {
                return false;
            }
        }
        return false;
    }

    public int hashCode() {
        int hash = NumberUtils.hash(this.m_description.hashCode(), this.a.hashCode());
        if (!isEmpty() && this.b != null) {
            int c = (this.m_description.c() - 2) * 2;
            for (int i = 0; i < c; i++) {
                hash = NumberUtils.hash(hash, this.b[i]);
            }
        }
        return hash;
    }

    public final double getXMin() {
        return this.a.xmin;
    }

    public final double getYMin() {
        return this.a.ymin;
    }

    public final double getXMax() {
        return this.a.xmax;
    }

    public final double getYMax() {
        return this.a.ymax;
    }

    public void setXMin(double d) {
        i();
        this.a.xmin = d;
    }

    public void setXMax(double d) {
        i();
        this.a.xmax = d;
    }

    public void setYMin(double d) {
        i();
        this.a.ymin = d;
    }

    public void setYMax(double d) {
        i();
        this.a.ymax = d;
    }

    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Envelope [m_envelope=");
        sb.append(this.a);
        sb.append(", m_attributes=");
        double[] dArr = this.b;
        sb.append(dArr != null ? Arrays.toString(Arrays.copyOf(dArr, Math.min(dArr.length, 3))) : null);
        sb.append("]");
        return sb.toString();
    }

    @Override // com.esri.core.geometry.Geometry
    public boolean isValid() {
        return this.a.isValid();
    }
}
